﻿using System;
using FlyWebFrame.Model;

namespace FlyWebFrame.Action.admin
{
    public class deletesubcat : baseaction
    {
        public override void Treat()
        {
            int Id;
            if (!Int32.TryParse(GetParameter(0), out Id))
            {
                Redirect("/admin/newslist");
            }

            Categories cat = new Categories();
            cat.id = Id;

            if (cat.Instance().Status && cat.parentId != 0)
            {
                Fly.Web.Resource.File img = new Fly.Web.Resource.File();
                img.FullPath = cat.image;
                img.Delete();

                cat.Delete();
                admin_script += "$('#msg-newsdelete').removeClass('hidden');";
            }
            else {
                admin_script += "$('#err-newsdelete').removeClass('hidden');";
            }
            Redirect("/admin/newscatlist");
        }
    }
}